package com.wxapp.market.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.market.api.pojo.vm.ad.PAdDetailVm;
import com.wxapp.market.api.pojo.vm.ad.PAdPageVm;
import com.wxapp.market.api.pojo.vm.ad.PAdSelectVm;
import com.wxapp.market.api.pojo.vo.ad.*;
import com.wxapp.market.service.service.AdService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "推送广告管理")
@RequestMapping("ad")
@RequiredArgsConstructor
public class AdController extends IBaseController {
    private final AdService adService;
    
    @PostMapping("add")
    @Operation(summary ="添加推送广告")
    public ResultVm<String> add(@RequestBody @Validated QAdAddVo qAdAddVo, @Schema(hidden = true) @User UserVo userVo) {
        return adService.add(qAdAddVo, userVo);
    }

    @PutMapping("update")
    @Operation(summary ="更新推送广告")
    public ResultVm<String> update(@RequestBody @Validated QAdUpdateVo qAdUpdateVo, @Schema(hidden = true) @User UserVo userVo) {
        return adService.update(qAdUpdateVo, userVo);
    }

    @PostMapping("page")
    @Operation(summary ="获取推送广告列表")
    public ResultVm<Page<PAdPageVm>> getPage(@RequestBody QAdPageVo qAdPageVo) {
        return adService.getPage(qAdPageVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="删除推送广告")
    public ResultVm<String> delete(@PathVariable String id) {
        return adService.delete(id);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary ="获取推送广告详细信息")
    public ResultVm<PAdDetailVm> detail(@PathVariable String id) {
        return adService.detail(id);
    }

    @GetMapping("/getSelect/{allData}")
    @Operation(summary ="广告选择框")
    public ResultVm<List<PAdSelectVm>> getSelect(@PathVariable boolean allData, @RequestParam(value = "name",required = false) String name) {
        return adService.getSelect(allData,name);
    }
}
